<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

class AutogeneratorControllerField extends JControllerForm {

    /**
     *
     * @var AutogeneratorModelField 
     */
    private $oModelField;
    
    private $oApp;

    public function __construct($config = array()) {
        parent::__construct($config);
        $this->oModelField = $this->getModel();
        $this->oApp = JFactory::getApplication();
    }

    public function changeStatus() {
        $iFieldId = $this->oApp->input->getInt('iFieldId');

        // Get table.
        $sMessage = $this->oModelField->changeStatus($iFieldId);

        echo $sMessage;
        die;
    }

    public function allowEditInList() {
        $iFieldId = $this->oApp->input->getInt('iFieldId');

        // Get table.
        $sMessage = $this->oModelField->allowEditInList($iFieldId);

        echo $sMessage;
        die;
    }

    public function editXmlTypeInline() {
        $aData = $this->oApp->input->get('data', array(), 'array');

        $sMessage = $this->oModelField->editXmlTypeInline($aData['id'], $aData['value']);

        echo $sMessage;
        die;
    }
    
    public function exportPHPFile() {
        $sFilePath = AUTOGENERATOR_DIR_CODE_TEMPLATE . 'administrator' . 
                DIRECTORY_SEPARATOR . 'views' . 
                DIRECTORY_SEPARATOR . 'views' . 
                DIRECTORY_SEPARATOR . 'view.html.tpl';

        if (JFile::exists($sFilePath))
        {
            $sContent = file_get_contents($sFilePath);
        }
        else
        {
            echo 'error path';
            die;
        }
        highlight_string($sContent);

        die;
    }

    public function setOrderingField()
    {
        $iFieldId = $this->oApp->input->getInt('iFieldId');

        // Get table.
        $sMessage = $this->oModelField->setOrderingField($iFieldId);

        echo $sMessage;
        die;
    }
    
}
